Skip to main content

Rule Priority (Salience)

note

Generated by ChatGPT, leaving it here for my own reference

Scenario

Imagine a discount system in an online store where multiple discount rules can apply, but you want to apply the most beneficial discount for the customer.

Rules with Priorities

  • Rule 1 (Priority: High): If a customer spends more than $500, they get a 20% discount.
  • Rule 2 (Priority: Medium): If a customer buys more than 3 items, they get a 15% discount.
  • Rule 3 (Priority: Low): All purchases get a 5% discount.

Priority Implementation

The system will first check for the rule with the highest priority and then proceed to lower priority rules.

Example Order of Evaluation

  • A customer makes a purchase of $600 with 4 items.
    • Evaluate Rule 1 (High Priority): Since the customer spends more than $500, this rule applies. The system grants a 20% discount.
    • Skip Rule 2 (Medium Priority): Even though the customer has bought more than 3 items, the higher priority rule (Rule 1) has already been applied. Depending on the system's design, you might stop further evaluation here, or you could evaluate this rule for potential stacking of discounts.
    • Skip Rule 3 (Low Priority): This is the fallback rule for any purchase, but since a higher-priority rule has been applied, this rule is skipped.

Conclusion

In this system, the customer receives the 20% discount from Rule 1, which is the most advantageous discount. The priority system ensures that the best possible discount is applied without the need for evaluating all rules, which can be more efficient and beneficial from a business standpoint.

Diagram Representation

[Customer Purchase: $600, 4 items]
|
|____ [Evaluate High Priority Rule: Rule 1 - 20% Discount]
| |
| [20% Discount Applied, Stop Further Evaluation]
|
|____ [Skip Medium Priority Rule: Rule 2 - 15% Discount]
|
|____ [Skip Low Priority Rule: Rule 3 - 5% Discount]

Summary

This simple example shows how rule priority ensures that the most important rules are evaluated first, providing an efficient way to manage multiple rules and ensuring the best outcome (in this case, the highest discount) is achieved without the need to process all possible rules.